home *** CD-ROM | disk | FTP | other *** search
Text File | 1998-10-11 | 2.5 KB | 158 lines | [TEXT/CWIE] |
- // CAMReminderData.cp -- document data
-
- #include "CAMReminderData.h"
-
- #include <LFileStream.h>
- #include "DDocData.h"
-
- //----------
- // initialize application data
-
- void CAMReminderData::InitAppData()
- {
- }
-
- //----------
- CAMReminderData::CAMReminderData()
- : LBroadcaster()
- {
- mDocData = nil;
- mFile = nil;
- mDirty = false;
- }
-
- //----------
- CAMReminderData::~CAMReminderData()
- {
- if (mDocData != nil) {
- delete mDocData;
- }
- CloseFile();
- }
-
- //----------
- void CAMReminderData::NewData ()
- {
- InitDocData();
- }
-
- //----------
- void CAMReminderData::OpenData (
- FSSpec* inMacFSSpec)
- {
- InitDocData();
- mFile = OpenFile (inMacFSSpec);
- ReadData();
- }
-
- //----------
- void CAMReminderData::InitDocData ()
- {
- mDocData = new DDocData;
- }
-
- //----------
- Boolean CAMReminderData::IsDirty ()
- {
- return mDirty;
- }
-
- //----------
- void CAMReminderData::DoSave ()
- {
- WriteData (mFile);
- }
-
- //----------
- void CAMReminderData::DoSaveAs (
- FSSpec* inMacFSSpec)
- {
- LFileStream* file;
-
- file = CreateFile (inMacFSSpec);
- if (file != nil) {
- WriteData (file);
- CloseFile (); // old file
- mFile = file;
- }
- }
-
- //----------
- void CAMReminderData::DoRevert ()
- {
- DisposeData();
- if (mFile != nil) {
- ReadData();
- }
- }
-
- //----------
- void CAMReminderData::CloseFile ()
- {
- if (mFile != nil) {
- delete mFile;
- mFile = nil;
- }
- }
-
- //----------
- // CreateFile is called in two situations:
- // 1. To Save a new untitled document
- // 2. To SaveAs to a new file
-
- LFileStream* CAMReminderData::CreateFile (
- FSSpec* inMacFSSpec)
- {
- LFileStream* file = new LFileStream (*inMacFSSpec);
-
- file->CreateNewDataFile (kSignature, kFileType);
- file->OpenDataFork (fsRdWrPerm);
-
- return file;
- }
-
- //----------
- LFileStream* CAMReminderData::OpenFile (
- FSSpec* inMacFSSpec)
- {
- LFileStream* file = new LFileStream (*inMacFSSpec);
-
- file->OpenDataFork (fsRdWrPerm);
-
- return file;
- }
-
- // The next few methods are for transferring data between the
- // data file and your internal data structures, and for disposing
- // your data structures. They are called by Open, Close, etc.
- // Replace their bodies with whatever is suitable for your application
-
- //----------
- void CAMReminderData::DisposeData ()
- {
- // delete your data structures
-
- mDirty = false;
- }
-
- //----------
- void CAMReminderData::ReadData ()
- {
- mDirty = false;
-
- mDocData->ReadFromFile (mFile);
- }
-
- //----------
- // WriteData is called in two situations:
- // 1. To Save the current document
- // 2. To SaveAs to a new file
-
- void CAMReminderData::WriteData (
- LFileStream* file)
- {
- mDirty = false;
-
- mDocData->WriteToFile (file);
- }
-